//
//  DCTaskViewController.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/11/28.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCTaskViewController.h"
#import "DCDispatchController.h"
#import "DCOrderReceiveController.h"
#import "DCSendingController.h"
#import "DCFinishedController.h"
#import "DCTaskNumBer.h"
@interface DCTaskViewController ()
@property (nonatomic, strong) ZWMSegmentController *segmentVC;
@property (nonatomic,strong) DCTaskNumBer *taskNum;
@end

@implementation DCTaskViewController

-(DCTaskNumBer *)taskNum {
    if (!_taskNum) {
        _taskNum = [DCTaskNumBer new];
    }
    return _taskNum;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    [NOTIFICATION addObserver:self selector:@selector(refreshTotalNum) name:@"refreshTaskTotalNum" object:nil];
//
//    [NOTIFICATION addObserver:self selector:@selector(refreshTotalNum123:) name:@"1234567890" object:nil];
    [self getData];
//    [self setUpMainVC];
}
-(void)getData {
    NSMutableDictionary *info = [NSMutableDictionary dictionary];
    __weak typeof(self) weakself = self;
    [DCServiceTool postWithUrl:getCarNum_URL params:info success:^(id responseObject) {
        if ([responseObject[@"code"] integerValue] == 0) {
            weakself.taskNum = [DCTaskNumBer mj_objectWithKeyValues:responseObject[@"record"]];
//            [weakself.segmentVC.view removeFromSuperview];
//            [weakself.segmentVC removeFromParentViewController];
            [weakself setUpMainVC];
            [weakself setUpBgViewIsShow:NO block:nil];
        }else {
            [weakself showMessage:responseObject[@"msg"] afterDelay:1.0];
            [weakself setUpBgViewIsShow:YES block:^{
                [weakself getData];
            }];
        }
        DCLog(@"responseObject---%@",responseObject);
    } failure:^(NSError *error) {
        [weakself setUpBgViewIsShow:YES block:^{
            [weakself getData];
        }];
    }];
}

- (void)setUpMainVC {
    
    DCDispatchController *dispatchVC = [[DCDispatchController alloc] init];
    DCOrderReceiveController *orderVC = [[DCOrderReceiveController alloc] init];
    DCSendingController *sendingVC = [[DCSendingController alloc] init];
    DCFinishedController *finishVC = [[DCFinishedController alloc] init];
    
    NSArray *array = @[dispatchVC,orderVC,sendingVC,finishVC];
    
    self.segmentVC = [ZWMSegmentController segmentControllerWithFrame:self.view.bounds Titles:@[@"待调度",@"待接单",@"运输中",@"已完成"] type:0];
    self.segmentVC.segmentView.showSeparateLine = YES;
    self.segmentVC.segmentView.segmentTintColor = BlueColor;
    self.segmentVC.viewControllers = [array copy];
    if (array.count==1) {
        self.segmentVC.segmentView.style=ZWMSegmentStyleDefault;
    } else {
        self.segmentVC.segmentView.style=ZWMSegmentStyleFlush;
    }
    [self.segmentVC  enumerateBadges:@[self.taskNum.prepareTaskNum,self.taskNum.waitTaskNum,self.taskNum.runningTaskNum,self.taskNum.completTaskNum]];
    [self addSegmentController:self.segmentVC];
    [self.segmentVC  setSelectedAtIndex:0];
}
//-(void)refreshTotalNum123:(NSNotification *)noti {
//    NSString *diaoduCount = noti.userInfo[@"diaoduCount"];
////    [self.segmentVC  enumerateBadges:@[Str_IsEmpty(diaoduCount)?@"":diaoduCount,Str_IsEmpty(self.taskNum.waitTaskNum)?@"":self.taskNum.waitTaskNum,Str_IsEmpty(self.taskNum.runningTaskNum)?@"":self.taskNum.runningTaskNum,Str_IsEmpty(self.taskNum.completTaskNum)?@"":self.taskNum.completTaskNum]];
//    self.taskNum.prepareTaskNum = diaoduCount;
//}
//-(void)refreshTotalNum {
//
//    [self getData];
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
